// 登录页面JS
function loginID() {
    var loginID = document.getElementById("login_po_ID");
    loginIDValue = loginID.value;
    var regex = /^[a-zA-Z\d]{8,}$/;
    if (!regex.test(loginIDValue) || loginIDValue == "") {
        alert("账号格式错误");
        loginID.classList.add("wrong");
        return false;
    }
    else {
        loginID.classList.remove("wrong");
        return true;
    }
}

function loginPW() {
    var loginPW = document.getElementById("login_po_pwd");
    loginPWValue = loginPW.value;
    var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/;
    if (!regex.test(loginPWValue) || loginPWValue == "") {
        alert("密码格式错误");
        loginPW.classList.add("wrong");
        return false;
    } else {
        loginPW.classList.remove("wrong");
        return true;
    }
}

function checkLogin() {
    if (loginID() && loginPW()) {
        return true;
    }
    else {
        return false;
    }
}

// 注册页面JS
function regID() {
    var regID = document.getElementById("reg_po_ID");
    regIDValue = regID.value;
    var regex = /^[a-zA-Z\d]{8,}$/;
    if (!regex.test(regIDValue) || regIDValue == "") {
        alert("账号格式错误");
        regID.classList.add("wrong");
        return false;
    }
    else {
        regID.classList.remove("wrong");
        return true;
    }
}

function regPwd() {
    var newPwd = document.getElementById("reg_po_pwd");
    if (newPwd.value.replace(/\s+/g, '') == "") {
        newPwd.classList.add("wrong");
        alert("密码不能位空！");
        return false;
    } else {
        var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/;
        if (regex.test(newPwd.value.replace(/\s+/g, ''))) {
            newPwd.classList.remove("wrong");
            return true;
        } else {
            newPwd.classList.add("wrong");
            alert("密码格式错误！");
            return false;
        }
    }
}

function regRePwd() {
    var newPwd = document.getElementById("reg_po_pwd");
    var renewPwd = document.getElementById("reg_po_repwd");
    if (regPwd()) {
        if (renewPwd.value.replace(/\s+/g, '') != newPwd.value.replace(/\s+/g, '')) {
            renewPwd.classList.add("wrong");
            alert("两次密码不一致！");
            return false;
        } else {
            renewPwd.classList.remove("wrong");
            return true;
        }
    }
}

function regName() {
    var userName = document.getElementById("reg_po_name");
    if (userName.value == "") {
        userName.classList.add("wrong");
        alert("用户昵称不能为空!");
        return false;
    } else {
        userName.classList.remove("wrong");
        return true;
    }
}

function regPhone() {
    var userPhone = document.getElementById("reg_po_phone");
    var regex = /^1[3-9]\d{9}$/;
    if (userPhone.value == "") {
        userPhone.classList.add("wrong");
        alert("手机号不能为空!");
        return false;
    } else {
        if (!regex.test(userPhone.value)) {
            userPhone.classList.add("wrong");
            alert("手机号格式不正确!");
            return false;
        } else {
            userPhone.classList.remove("wrong");
            return true;
        }
    }
}

function checkReg() {
    if (regID() && regName() && regPwd() && regRePwd() && regPhone()) {
        return true;
    } else {
        return false;
    }
}


// 找回密码页面JS
function resetID() {
    var regID = document.getElementById("reset_po_ID");
    regIDValue = regID.value;
    var regex = /^[a-zA-Z\d]{8,}$/;
    if (!regex.test(regIDValue) || regIDValue == "") {
        alert("账号格式错误");
        regID.classList.add("wrong");
        return false;
    }
    else {
        regID.classList.remove("wrong");
        return true;
    }
}

function resetPwd() {
    var newPwd = document.getElementById("reset_po_pwd");
    if (newPwd.value.replace(/\s+/g, '') == "") {
        newPwd.classList.add("wrong");
        alert("密码不能位空！");
        return false;
    } else {
        var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/;
        if (regex.test(newPwd.value.replace(/\s+/g, ''))) {
            newPwd.classList.remove("wrong");
            return true;
        } else {
            newPwd.classList.add("wrong");
            alert("密码格式错误！");
            return false;
        }
    }
}

function resetRePwd() {
    var newPwd = document.getElementById("reset_po_pwd");
    var renewPwd = document.getElementById("reset_po_repwd");
    if (resetPwd()) {
        if (renewPwd.value.replace(/\s+/g, '') != newPwd.value.replace(/\s+/g, '')) {
            renewPwd.classList.add("wrong");
            alert("两次密码不一致！");
            return false;
        } else {
            renewPwd.classList.remove("wrong");
            return true;
        }
    }
}

function resetPhone() {
    var userPhone = document.getElementById("reset_po_phone");
    var regex = /^1[3-9]\d{9}$/;
    if (userPhone.value == "") {
        userPhone.classList.add("wrong");
        alert("手机号不能为空!");
        return false;
    } else {
        if (!regex.test(userPhone.value)) {
            userPhone.classList.add("wrong");
            alert("手机号格式不正确!");
            return false;
        } else {
            userPhone.classList.remove("wrong");
            return true;
        }
    }
}

function checkReset() {
    if (resetID() && resetPwd() && resetRePwd() && resetPhone()) {
        return true;
    }else{
        return false;
    }
}